package com.log.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName BaseUtils
 * @Author xiezhuocai
 * @Description TODO
 * @Date 2022/5/11 20:41
 */
public class CommonUtils {

    /**
     *  取target中在front和queen区间值
     * @param target 目标字符
     * @param front 前
     * @param queen 后
     * @return 前-后之间的字符
     */
    public static List<String> section(String target, char front, char queen){
        List<String> key = new ArrayList<>();
        char[] chars = target.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i] == front){
                StringBuilder stringKey = new StringBuilder();
                for (;i < chars.length;){
                    stringKey.append(chars[i]);
                    if(chars[i++] == queen){
                        key.add(stringKey.toString().substring(1,stringKey.toString().length()-1));
                        break;
                    }
                }

            }
        }
        return key;
    }

    public static Map<String,String> consanguinity(List<String> keys,Map<String,String> data){
        Map<String,String> result = new HashMap<>();
        for (String key : keys) {
            String value = data.get(key);
            if(value!=null){
                result.put(key,data.get(key));
            }
        }
        return result;
    }


}
